module.exports = {
	/**
	 * 添加单条数据
	 * @url admin/pages/kh/xcxpz/xcxgl/add 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @params {Number} code 错误码，0表示成功
	 * @params {String} msg 详细信息
	 */
	main: async (event) => {
		const db = uniCloud.database();

		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			_
		} = util;
		let {
			uid
		} = data;
		let res = {
			code: 0,
			msg: 'ok'
		};
		// 业务逻辑开始-----------------------------------------------------------
		// 获取前端传过来的参数
		let {
			xcxinfo
		} = data
		let {
			dykefu,
			testkkaiguan,
			simplified,
			recharge_instructions,
			pid,
			mfld_image,
			freeBean,
			payMoney,
			receiveTime,
			originid,
			appid,
			appname,
			appsecret,
			iospay,
			gzhurl,
			tgemail,
			workwxappid,
			workwxurl,
			qrurl,
			opensearch,
			staticInvite_code,
			beannumber,
			signin_reward,
			xspsx,
			flhd,
			jjgx,
			index_tips_switch,
			index_tips_text,
			gzhTip, //追剧页关注公众号提示开关
			gzhTipText, //追剧页关注公众号提示文字
			tips_switch,
			tips_text,
			gzgzh_tip, //关注公众号提示文字
			wxad_switch,
			wxad_adid,
			wxad_maxlimit,
			wxad_reward,
			wxad_rule,
			signin_image,
			remark,
			beanyhq,
			twoInRow,
			_add_time,
			_add_time_str

		} = xcxinfo;
		// 参数验证开始


		//检查数据库里是否已有同样的appid或appname,不允许添加重复数据
		let checkAppid = await db.collection('a_appid').where({
			appid: appid
		}).get()
		let checkAppname = await db.collection('a_appid').where({
			appname: appname
		}).get()

		if (checkAppid.data.length > 0 || checkAppname.data.length > 0) {
			res.code = 1;
			res.msg = '小程序appid或小程序名称与已有数据重复';
			return res;
		}


		// 参数验证结束
		let dbName = "a_appid"; // 表名
		// 执行 数据库add 命令
		res.id = await vk.baseDao.add({
			dbName,
			dataJson: {
				dykefu,
				testkkaiguan,
				simplified,
				recharge_instructions,
				pid,
				mfld_image,
				freeBean,
				payMoney,
				receiveTime,
				originid,
				appid,
				appname,
				appsecret,
				iospay,
				gzhurl,
				tgemail,
				workwxappid,
				workwxurl,
				qrurl,
				opensearch,
				staticInvite_code,
				beannumber,
				signin_reward,
				xspsx,
				flhd,
				jjgx,
				gzhTip, //追剧页关注公众号提示开关
				gzhTipText, //追剧页关注公众号提示文字
				index_tips_switch,
				index_tips_text,
				tips_switch, //player页面右上角提示开关
				tips_text, //player页面右上角提示文字
				gzgzh_tip, //播放页关注公众号提示文字
				wxad_switch,
				wxad_adid,
				wxad_maxlimit,
				wxad_reward,
				wxad_rule,
				signin_image,
				remark,
				twoInRow,
				beanyhq,
				_add_time,
				_add_time_str
			}
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}